cmake_minimum_required(VERSION 3.8)
project(perception_ros2_driver)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(pcl_conversions REQUIRED)
find_package(rosidl_default_generators REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

find_package(PCL REQUIRED COMPONENTS common filters)
find_package(Protobuf REQUIRED)
find_package(cpprestsdk REQUIRED)
find_package(PkgConfig)
pkg_search_module(OPENSSL openssl)

rosidl_generate_interfaces(${PROJECT_NAME}
  "msg/Status.msg"
  "msg/Target.msg"
  "msg/Targets.msg"
)

add_executable(perception_ros2_driver_node src/main.cpp src/node.cpp proto/detection.pb.cc)
target_include_directories(perception_ros2_driver_node PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/proto>
  $<INSTALL_INTERFACE:include>)
target_compile_features(perception_ros2_driver_node PUBLIC c_std_99 cxx_std_17)  # Require C99 and C++17

if(${rosidl_cmake_VERSION} VERSION_LESS 2.5.0)
  rosidl_target_interfaces(perception_ros2_driver_node
    ${PROJECT_NAME} "rosidl_typesupport_cpp")
else()
  rosidl_get_typesupport_target(
    cpp_typesupport_target ${PROJECT_NAME} "rosidl_typesupport_cpp")
  target_link_libraries(perception_ros2_driver_node "${cpp_typesupport_target}")
endif()

ament_target_dependencies(perception_ros2_driver_node
  rclcpp
  rclcpp_components
  sensor_msgs
  pcl_conversions
)

install(TARGETS perception_ros2_driver_node
  DESTINATION lib/${PROJECT_NAME})

install(DIRECTORY
  launch
  DESTINATION share/${PROJECT_NAME}/
)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

target_link_libraries(perception_ros2_driver_node ${PCL_LIBRARIES} ${PROTOBUF_LIBRARIES} cpprestsdk::cpprest ${OPENSSL_LDFLAGS})
target_link_directories(perception_ros2_driver_node PRIVATE ${PCL_LIBRARY_DIRS})

ament_package()
